package jsyf.oa.service.system;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.fastjson.JSONObject;
import jsyf.com.dao.BaseJdbcDao;
import jsyf.oa.dao.system.User2RightOpDao;
import jsyf.oa.entity.system.User2RightOpEntity;
import jsyf.oa.facade.system.User2RightOpFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Lenovo on 2017/12/11.
 */
@Service
@Transactional(rollbackFor = Exception.class)
@com.alibaba.dubbo.config.annotation.Service(protocol = {"dubbo"})
public class User2RightOpService implements User2RightOpFacade {
    @Autowired
    private User2RightOpDao dao;
    @Override
    public Boolean config(String userId, String rightOpIds) {
        dao.removeByCondition(" AND USER_ID = ? ",new String[]{userId});
        if (!StringUtils.isEmpty(rightOpIds)) {
            List<String> list = BaseJdbcDao.stringToList(rightOpIds);
            for (int i = 0; i < list.size(); i++) {
                User2RightOpEntity entity = new User2RightOpEntity();
                entity.setUserId(userId);
                entity.setRightOpId(list.get(i));
                dao.add(entity);
            }
        }
        return true;
    }

    @Override
    public List<JSONObject> getByUserId(String roleNameId) {
        return dao.getJSONListByCondition(" AND USER_ID = ? ",new Object[]{roleNameId});
    }
}
